package Run;

import Chess.MoveStrategy;
import Chess.chessPiece;
import Chess.chessType;

public class RookStrategy implements MoveStrategy {
    public boolean move(chessPiece currentChessPiece,int[][] chess,int x,int y){
    	int number=0;
        int ax = currentChessPiece.getX();
        int ay = currentChessPiece.getY();
        	if(x==ax){
        		if(ay>y){
        			for(int i=(ay-1);i>y;i--){
        				if(chess[i][x]!=0){
        					number++;
        					break;
        				}
        			}
        		}
        		else if(ay<y){
        			for(int i=(ay+1);i<y;i++){
        				if(chess[i][x]!=0){
        					number++;
        					break;
        				}
        			}
        		}
        	}
        	
        	if(y==ay){
        		if(ax>x){
        			for(int i=(ax-1);i>x;i--){
        				if(chess[y][i]!=0){
        					number++;
        					break;
        				}
        			}
        		}
        		else if(ax<x){
        			for(int i=(ax+1);i<x;i++){
        				if(chess[y][i]!=0){
        					number++;
        					break;
        				}
        			}
        		}
        	}
        	
        	if(number==0){
        		currentChessPiece.move(x, y);
        		return true;
        	}
        	else 
        		return false;
        }
   }

